package tools

//Tools' instances

var (
	structTool StructTool = StructTool{}
	nameTool   NameTool   = NameTool{}
	timeTool   TimeTool   = TimeTool{}
	stockTool  StockTool  = StockTool{}
)

//Interfaces called by other modules

//Transfer struct's fields to a map by using reflect, zero field will be ignored;
//the keys's name in map will be snake style, instead of Camel style in struct
func StructToMap(data interface{}) map[string]interface{} {
	return structTool.StructToMap(data)
}

func MapToStruct(m map[string]interface{}, st interface{}) {
	structTool.MapToStruct(m, st)
}

//wowCoupon:1000
func GenRedisKeyBusiness(business_id int64) string {
	return stockTool.GenRedisKeyBusiness(business_id)
}

//JD1008989900:100:stock
func GenRedisHashKeyStock(good_id, id int64) string {
	return stockTool.GenRedisHashKeyStock(good_id, id)
}

//JD1008989900:100:stock by key
func GenRedisHashKeyStockByStr(key string) string {
	good_id, id := stockTool.GetGoodIDMetaID(key)
	return stockTool.GenRedisHashKeyStock(good_id, id)
}

//JD1008989900:100:is
func GenRedisHashKeyIssueStartTime(good_id, id int64) string {
	return stockTool.GenRedisHashKeyIssueStartTime(good_id, id)
}

//JD1008989900:100:is by key
func GenRedisHashKeyIssueStartTimeByStr(key string) string {
	good_id, id := stockTool.GetGoodIDMetaID(key)
	return stockTool.GenRedisHashKeyIssueStartTime(good_id, id)
}

//JD1008989900:100:ie
func GenRedisHashKeyIssueEndTime(good_id, id int64) string {
	return stockTool.GenRedisHashKeyIssueEndTime(good_id, id)
}

//JD1008989900:100:ie by key
func GenRedisHashKeyIssueEndTimeByStr(key string) string {
	good_id, id := stockTool.GetGoodIDMetaID(key)
	return stockTool.GenRedisHashKeyIssueEndTime(good_id, id)
}

//RobberList:1000:JD1008989900:100
func GenRedisKeyUserIdList(businessID, goodID, ID int64) string {
	return stockTool.GenRedisKeyRobberList(businessID, goodID, ID)
}

//Get good_id and id by a string key JD1008989900:100:ie -> JD1008989900, 100
func GetGoodIDMetaID(key string) (good_id int64, id int64) {
	return stockTool.GetGoodIDMetaID(key)
}

//Get business id by a string key wowCoupon:1000 -> 1000
func GetBusinessID(key string) (businessID int64) {
	return stockTool.GetBusinessID(key)
}

//local time string to second timestamp
func StringToStamp(timestr string) (int64, error) {
	return timeTool.StringToStamp(timestr)
}

func StampToString(timeStamp int64) string {
	return timeTool.StampToString(timeStamp)
}
